﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using AncientLand.Controllers;
using AncientLand.Service.Entity;

namespace AncientLand.Web
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : System.Web.HttpApplication
    {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
            filters.Add(new HandleErrorAttribute());
        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.IgnoreRoute("elmah.axd");
            routes.IgnoreRoute("{*alljs}", new { alljs = @".*\.js?" });
            routes.IgnoreRoute("{*allashx}", new { allashx = @".*\.ashx?" });
            routes.IgnoreRoute("{*allhtml}", new { allhtml = @".*\.htm?" });
            routes.IgnoreRoute("{*allcss}", new { allcss = @".*\.css?" });
            routes.IgnoreRoute("{*allimages}", new { allimages = @".*\.ico?|.*\.jpg?|.*\.png?|.*\.gif?" });

            routes.MapRoute(
                "contact-us", // 联系我们
                "contact-us", // 带有参数的 URL
                new { controller = "Message", action = "ContactUs", id = UrlParameter.Optional } // 参数默认值
            );
            routes.MapRoute(
                "views and suggestion", // 意见和建议
                "views-suggestion", // 带有参数的 URL
                new { controller = "Message", action = "Suggestions", id = UrlParameter.Optional } // 参数默认值
            );
            routes.MapRoute(
                "About-us", // 关于我们
                "about-us", // 带有参数的 URL
                new { controller = "Default", action = "AboutUs", id = UrlParameter.Optional } // 参数默认值
            );
            
            routes.MapRoute(
                "tips", // 温馨提示
                "tips", // 带有参数的 URL
                new { controller = "Default", action = "Tips", id = UrlParameter.Optional } // 参数默认值
            );
             routes.MapRoute(
                "PackageServices", // 套餐服务
                "Package-Services", // 带有参数的 URL
                new { controller = "Default", action = "PackageServices", id = UrlParameter.Optional } // 参数默认值
            );

            routes.MapRoute(
               "PhotoShow", // 作品展示
               "photograph-show/portrait/", // 带有参数的 URL
               new { controller = "Pictorial", action = "List"} // 参数默认值
           );
            routes.MapRoute(
               "PhotoShow-wedding", // 作品展示
               "photograph-show/wedding-dress/", // 带有参数的 URL
               new { controller = "Wedding", action = "List"} // 参数默认值
           );

           routes.MapRoute(
               "PhotosUpload", // 作品展示
               "photos/Upload", // 带有参数的 URL
               new { controller = "ShowCase", action = "UploadPhotos", id = UrlParameter.Optional } // 参数默认值
           );

           routes.MapRoute(
             "PhotosUpload2", // 作品展示
             "photos/Upload1", // 带有参数的 URL
             new { controller = "ShowCase", action = "UploadPhotos1", id = UrlParameter.Optional } // 参数默认值
         );

           routes.MapRoute(
               "PhotosUpload1", // 作品展示
               "Admin/Login", // 带有参数的 URL
               new { controller = "Admin", action = "Login", category = UrlParameter.Optional } // 参数默认值
           );

            routes.MapRoute(
                "Default", // 默认
                "{controller}/{action}/{id}", // 带有参数的 URL
                new { controller = "Home", action = "Index", id = UrlParameter.Optional } // 参数默认值
            );


            routes.MapRoute(
             "404-PageNotFound",
             "{*catchall}",
             new { controller = "Home", action = "Error" }
         );

        }

        protected void Application_Start()
        {
            //Database.SetInitializer(new DbContextInitializer());
            //ModelMetadataProviders.Current = new DataAnnotationsModelMetadataProvider();
            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
            ControllerBuilder.Current.SetControllerFactory(WindsorControllerFactory.Instance);
        }
    }
}